package image;

import java.util.HashMap;

public class PixelArray {

	private HashMap<Integer, HashMap> pixelRows = new HashMap<Integer, HashMap>();
	private int width = 0;
	private int height = 0;
	
	public void add(int x, int y, int value) {
		// If row does not exist, create new row.
		if (!pixelRows.containsKey((Integer)y)) {
			pixelRows.put((Integer)y, new HashMap<Integer, Integer>());
		}
		// Add value to hashmap.
		pixelRows.get((Integer)y).put((Integer)x, (Integer)value);
	}
	
	public int get(int x, int y) {
		// If value for coordinate exists in hashmap.
		if (pixelRows.containsKey((Integer)y) && pixelRows.get((Integer)y).containsKey((Integer)x)) {
			return (Integer) pixelRows.get((Integer)y).get((Integer)x);
		}
		return 0;
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public void setWidth(int width) {
		this.width = width;
	}
	
	public void setHeight(int height) {
		this.height = height;
	}
	
	public boolean isHeightSet() {
		return height != 0;
	}
	
	public boolean isWidthSet() {
		return width != 0;
	}
}
